package main

import (
	"log"
	"os"
	"text/template"
)

func check(err error) {
	if err != nil {
		log.Fatal(err)
	}
}

func execuTemplate(text string, data interface{}) {
	tmpl, err := template.New("test").Parse(text)
	check(err)
	err = tmpl.Execute(os.Stdout, data)
	check(err)

}

func main() {
	info := " this is {{.}} http templates\n"
	// tmpl, err := template.New("test").Parse(info)
	// check(err)
	// err = tmpl.Execute(os.Stdout, "ABC")
	// check(err)
	// err = tmpl.Execute(os.Stdout, 42)
	// check(err)
	// err = tmpl.Execute(os.Stdout, true)
	// check(err)
	execuTemplate(info, "abcdefg")
	execuTemplate(info, 12345)
	execuTemplate(info, true)
	execuTemplate(info, []string{"aaa", "bbb"})

	execuTemplate("My name is :{{.}}!\n", "hujianli")
	execuTemplate("My name is :{{.}}!\n", 3.1415926)

	execuTemplate("start {{if .}}Dot is true!{{end}} finish!!\n", true)
	execuTemplate("start {{if .}}Dot is true!{{end}} finish!!\n", false)

}
